import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, ExecuteButton, SynchronizeButton } from '../Common/options'

export const ScoreManagement003 = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '项目评分',
        pageSize: 10,
        params: { pageIndex: 1, scoreType: 2, OrderField: 'yearMonth@desc,projectUuid@asc' },
        get: API_LIST()[`getScoreManagement`],
        added: `posScoreManagement`,
        modify: `putScoreManagement`,
        delete: `delScoreManagement`,
        initialValues: { scoreType: 2 },
        options: [
            Permission.findIndex(v => v.uuid === 'a5ae3433-c715-436c-8a98-c4aa3121687b') !== -1 && (
                <SynchronizeButton
                    title="上传评分"
                    type="primary"
                    smallTitle="上传项目评分"
                    OptionsEvent={OptionsEvent}
                    data={{
                        url: 'posBCCenterPushPushScoreManagement',
                        type: 2,
                    }}
                />
            ),
            Permission.findIndex(v => v.uuid === '5c2eac6a-36f8-41e6-aa20-fb8de2172737') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            {
                dataIndex: 'scoreType',
                title: '评分类型',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            commonTableList.uuid,
            {
                dataIndex: 'projectUuid',
                title: '项目名称',
                valueType: 'select',
                valueEnum: ClientData.project,
                rules: true,
                width: 450,
            },
            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                picker: 'month',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: ClientData.organization,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'organizationScore',
                title: '评分',
                valueType: 'input',
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'parentUuid',
                title: '分数类型',
                valueType: 'select',
                valueEnum: { 0: '人工评分', 1: '系统生成' },
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'isEnabled',
                title: '审核状态',
                valueType: 'select',
                valueEnum: BuiltInData.Pass,
                hideInAdded: true,
                hideInModify: true,
                rules: true,
                width: 150,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 250,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, projectUuid, yearMonth, scoreType, isEnabled } = record
                    const statusText = isEnabled === 0 ? '通过' : '不通过'
                    const tipsText = `${statusText}成功!`
                    return [
                        Permission.findIndex(v => v.uuid === 'c6de235c-74ea-4e9b-a239-5aacf169aa19') !== -1 &&
                            isEnabled === 0 && (
                                <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                            ),
                        Permission.findIndex(v => v.uuid === '6b9c7570-4777-4131-9ff0-d07235b96367') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="one"
                                title={statusText}
                                danger={isEnabled}
                                url="posScoreManagementUpdateIsEnabled"
                                path={[projectUuid, yearMonth, isEnabled === 0 ? 1 : 0, scoreType]}
                                tips={tipsText}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'f4949edb-32b3-41ea-a145-12fdf96aae75') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="ScoreManagement"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
